package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.wicket.okrapp.base.service.MOmsEvaluationTemplateSetService;
import com.wicket.okrapp.base.service.dto.req.QueryEvaTempSetDetailReq;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsEvaluationTemplateSetMapper;
import com.wicket.okrapp.dal.po.mbg.OmsEvaluationTemplateSet;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsEvaluationTemplateSetServiceImpl
        extends ServiceImpl<OmsEvaluationTemplateSetMapper, OmsEvaluationTemplateSet>
        implements MOmsEvaluationTemplateSetService {

    @Autowired
    OmsEvaluationTemplateSetMapper omsEvaluationTemplateSetMapper;

    /**
     * 3-2-02-01修改评价模板设置[2485]
     */
    @Trace(operationName = "3-2-02-01修改评价模板设置")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateEvaTempSet(OmsEvaluationTemplateSet omsEvaluationTemplateSet) {

        return super.updateById(omsEvaluationTemplateSet);
    }

    /**
     * 3-2-02-01新增评价模板设置[2442]
     */
    @Trace(operationName = "3-2-02-01新增评价模板设置")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addEvaTempSet(OmsEvaluationTemplateSet omsEvaluationTemplateSet) {
        omsEvaluationTemplateSet.setEvaTempSetId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsEvaluationTemplateSet.setSubjectLifeCycle("EDITING");
        omsEvaluationTemplateSet.setIsArchive("FALSE");
        omsEvaluationTemplateSet.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsEvaluationTemplateSet.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsEvaluationTemplateSet.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsEvaluationTemplateSet.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsEvaluationTemplateSet.setIsValid("FALSE");
        omsEvaluationTemplateSet.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        omsEvaluationTemplateSet.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if (super.save(omsEvaluationTemplateSet)) {
            return omsEvaluationTemplateSet.getEvaTempSetId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-2-02-01查评价模板设置详情[2363]
     */
    @Trace(operationName = "3-2-02-01查评价模板设置详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsEvaluationTemplateSet queryEvaTempSetDetail(QueryEvaTempSetDetailReq reqDto) {

        try {
            reqDto.setIsValid("FALSE");
            Map<String, Object> columnMap = CommonFunctionHelper.objectToMap(reqDto);
            List<OmsEvaluationTemplateSet> retList = (List<OmsEvaluationTemplateSet>) super.listByMap(columnMap);
            if (retList == null || retList.size() <= 0) return null;
            OmsEvaluationTemplateSet ret = retList.get(0);

            return ret;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }

    }
}
